<template>
  <el-scrollbar ref="scrollContainer"
                :vertical="false"
                class="scroll-container"
                @wheel.native.prevent="handleScroll">
    <slot />
  </el-scrollbar>
</template>

<script>

export default {
  name: 'ScrollPane',
  data () {
    return {
      left: 0
    }
  },
  computed: {
    scrollWrapper () {
      return this.$refs.scrollContainer.$refs.wrap
    }
  },
  mounted () {
    this.scrollWrapper.addEventListener('scroll', this.emitScroll, true)
  },
  beforeDestroy () {
    this.scrollWrapper.removeEventListener('scroll', this.emitScroll)
  },
  methods: {
    handleScroll (e) {
      const eventDelta = e.wheelDelta || -e.deltaY * 40
      const $scrollWrapper = this.scrollWrapper
      $scrollWrapper.scrollLeft = $scrollWrapper.scrollLeft + eventDelta / 4
    },
    emitScroll () {
      this.$emit('scroll')
    }

  }
}
</script>

<style lang="scss" scoped>
.scroll-container {
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  max-width: 100%;
  ::v-deep {
    .el-scrollbar__bar {
      bottom: 0px;
      transition: opacity 0.34s ease-out;
      opacity: 0;

    }
    .el-scrollbar__wrap {
      height: 49px;
    }
  }
  &:hover {
    ::v-deep {
      .el-scrollbar__bar {
        opacity: 1;
      }
    }
  }
}
</style>
